<template>
  <!-- 个人中心页 -->
  <div class="personal">
    <router-link :to="'/profile/' + $route.params.id">
      <div class="profile">
        <!-- $axios.defaults.baseURL读取axios的服务器路径 -->
        <img :src="call.head_img" alt />
        <div class="profile-center">
          <div class="name">
            <span
              :class="{
                iconfont: true,
                iconxingbienan: call.gender == 0,
                iconxingbienv: call.gender == 1,
              }"
            ></span
            >{{ call.nickname }}
          </div>
          <div class="time">{{ call.create_data | time_filter }}</div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <hmcell
      title="我的关注"
      desc="关注的用户"
      @click="$router.push({ name: 'collection' })"
    ></hmcell>
    <hmcell title="我的跟帖" desc="跟帖/回复"></hmcell>
    <hmcell
      title="我的收藏"
      desc="文章/视频"
      @click="$router.push({ name: 'collection_page' })"
    ></hmcell>
    <hmcell title="设置"></hmcell>
    <hmbutton class="btn" @click="exit">退出</hmbutton>
  </div>
</template>

<script>
import hmcell from "@/components/hmcell.vue";
import hmbutton from "@/components/hmbutton.vue";
import { myuser } from "@/apis/user.js";
import axios from "@/utils/myaxios.js";
import { time_filter } from "@/utils/time_filter.js";
export default {
  components: {
    hmbutton,
    hmcell,
  },
  filters: {
    time_filter,
  },
  data() {
    return {
      call: {},
    };
  },
  async mounted() {
    try {
      let res = await myuser(this.$route.params.id);

      if (res.data.message == "获取成功") {
        res.data.data.head_img =
          axios.defaults.baseURL + res.data.data.head_img;

        this.call = res.data.data;
      }
    } catch (err) {
      this.$toast.fail("获取数据失败");
    }
  },
  methods: {
    exit() {
      localStorage.removeItem("mytoken");
      localStorage.removeItem("mimas");
      this.$router.push({ path: "/index" });
    },
  },
};
</script>

<style lang="less" scoped>
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;

  img {
    width: 70 / 360 * 100vw;
    height: 70 / 360 * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    span {
      color: #75b9eb;
    }
  }
  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}

.btn {
  margin: 20px auto;
  background-color: #f00;
}
</style>